package chapter5.homework.GeometryCalc;

import java.util.InputMismatchException;
import java.util.Scanner;

class Circle {

    public static int getCounter() {
        return counter;
    }

    static int counter;

    static void count() {
        counter++;
    }
    static boolean calc(){
        Scanner scanner=new Scanner(System.in);
        Circle circle=null;
        double radius;
        while(true){
            try{
                System.out.println("请输入半径");
                radius=scanner.nextDouble();
                if(radius<=0){
                    System.out.println("半径输入无效，请再试一次");
                }
                else{
                    circle=new Circle(radius);
                    circle.showResult();
                    circle.count();
                    return true;
                }
            }
            catch (InputMismatchException ime){
                System.out.println("请输入数字！");
            }
        }
    }

    public final double PI = 3.1415927;
    double radius;

    Circle(double r) {
        this.radius = r;
    }

    double S() {

        return PI * this.radius * this.radius;
    }

    double C() {

        return 2 * PI * this.radius;
    }
    void showResult(){
        System.out.println("该圆周长：\t"+this.C());
        System.out.println("面积：\t\t"+this.S());
    }

}
